<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->bigInteger('agent_id')->index()->comment('代理商ID');
            $table->bigInteger('user_id')->index()->comment('用户ID');
            $table->string('order_no', 32)->unique()->comment('订单号');
            $table->bigInteger('product_id')->index()->comment('商品ID');
            $table->string('product_name', 64)->comment('商品名称');
            $table->string('product_logo_url', 256)->comment('商品封面图');
            $table->integer('quantity')->comment('购买数量');
            $table->integer('sale_price')->comment('销售单价: 单位元');
            $table->integer('order_amount')->comment('订单金额: 单位元');
            $table->boolean('is_resale')->comment('是否是转售订单');
            $table->string('order_status')->comment('订单状态');
            $table->string('trans_status')->nullable()->comment('资产转移状态');
            $table->string('trans_fail_reason')->nullable()->comment('资产转移失败原因');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
